每个设备文件都支持系统调用 ioctl

  ioctl
目标 控制一个设备
头文件 #include <sys/ioctl.h>
原型 int result = ioctl(int fd, int operation [, arg...]);
参数 fd 设备文件描述符, operation 操作, arg... 操作所需要的参数
返回值 -1 error, other 依设备而定

下面代码显示屏幕尺寸

#include <stdio.h>
#include <sys/ioctl.h>
void print_screen_dimensions()
{
    struct winsize wbuf;
    if (ioctl(0, TIOCGWINSZ, &wbuf) != -1){
        printf("%d row x %d cols\n", wbuf.ws_row, wbuf.ws_col);
        printf("%d wide x %d tall\n", wbuf.ws_xpixel, wbuf.ws_ypixel);
    }
}

符号 TIOCGWINSZ 是函数代码